package servlet;

import model.User;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;
import java.util.Date;

@WebServlet(name = "userChangeInformation", urlPatterns = "/userChangeInformation")
@MultipartConfig(
        fileSizeThreshold = 1024 * 1024, // 1 MB，超过的文件写入磁盘，不写入内存
        maxFileSize = 1024 * 1024 * 10,  // 10 MB 单个文件最大
        maxRequestSize = 1024 * 1024 * 15 // 15 MB 整个表单请求最大
)

public class UserChangeInformationServlet extends HttpServlet {
    private UserService userService = new UserService();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");

        //访问用户中心时，用户必须先登录，否则实施拦截
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        if(user == null) {
            response.sendRedirect(request.getContextPath() + "/user_login.jsp");
            return;
        }

        //获取前端用户表单数据
        String nickname = request.getParameter("changeNickname");
        String username = request.getParameter("changeUsername");
        String phone_number = request.getParameter("changePhone_number");
        Part avatarPart = request.getPart("changeAvatar");

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
